package com.dingli.controller;

import com.dingli.framework.entity.Resume;
import com.dingli.framework.entity.Undertake;
import com.dingli.framework.util.Response;
import com.dingli.service.IUndertakeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/undertake")
@Api(tags = "项目服务管理")
public class UndertakeController {

    @Autowired
    private IUndertakeService iUndertakeService;

    @GetMapping("/selectList")
    @ApiOperation("项目服务信息列表查询")
    public Response<PageInfo<Undertake>> selectList(@ApiParam("查询条件")
                                                    @RequestParam(required = false) String search,
                                                    @ApiParam("页码") @RequestParam(required = false) Integer pageNum,
                                                    @ApiParam("页面大小")
                                                    @RequestParam(required = false) Integer pageSize) {
        return iUndertakeService.selectList(search, pageNum, pageSize);
    }

    @GetMapping("/selectAll")
    @ApiOperation("项目信息详情查看")
    public Response<List<Undertake>>selectAll(@ApiParam("项目ID") @RequestParam Long ukeId) {
        return iUndertakeService.selectAll(ukeId);
    }

    @PostMapping("/updateState")
    @ApiOperation("项目审核通过")
    public Response<Object> updateState(@ApiParam("审核通过") @RequestBody String ukeId) {

        return iUndertakeService.updateState(ukeId);
    }

    @PostMapping("/update")
    @ApiOperation("项目审核不通过")
    public Response<Object> update(@ApiParam("审核不通过") @RequestBody String ukeId) {
        return iUndertakeService.update(ukeId);
    }

    @RequestMapping ("/select")
    @CrossOrigin
    @ApiOperation("查询所有不通过项目")
    public HashMap<Object, Object> select(@ApiParam("项目不通过") @RequestParam String ukeId){
        Response<List<Undertake>> list = iUndertakeService.select("123456");
        HashMap<Object, Object> undertake = new HashMap<>();
        undertake.put("Undertake",list);
        undertake.put("size",list.getData().size());
        return undertake;
    }

    @RequestMapping ("/selectName")
    @CrossOrigin
    @ApiOperation("项目模糊查询")
    public Response<List<Undertake>> selectName(@ApiParam("关键字检索") @RequestParam String typeName){
        return iUndertakeService.selectName(typeName);
    }

    @PostMapping("/insert")
    @ApiOperation("服务信息新增")
    public Object insert(@ApiParam("服务信息") @RequestBody Undertake undertake) {
        return iUndertakeService.insert(undertake);
    }

    @PostMapping("/updateById")
    @ApiOperation("服务信息修改")
    public Response<Object> updateById(@ApiParam("修改服务信息") @RequestBody Undertake undertake) {

        return iUndertakeService.updateById(undertake);
    }

    @GetMapping("/deleteById")
    @ApiOperation("服务信息删除")
    public Response<Object> deleteById(@ApiParam("服务ID") @RequestParam Long ukeId) {
        return iUndertakeService.deleteById(ukeId);
    }

}